require(['swiper','common'],function (Swiper) {
  // 轮播图
  var travelswiper = new Swiper('.gzl-swiper_custom', {
    loop: true,
    speed: 500,
    autoplay: {
      disableOnInteraction: false
    },
    pagination: {
      el: '.swiper-pagination',
      type: 'fraction'
    }
  });
  // 排期
  $.calendar({
    type: 'travel',
    self: $(".travel-calendar"),
    nav: {
      '2018-11': parseInt(Math.random() * 10000),
      '2018-12': parseInt(Math.random() * 10000),
      '2019-01': parseInt(Math.random() * 10000),
      '2019-02': parseInt(Math.random() * 10000),
      '2019-03': parseInt(Math.random() * 10000)
    },
    date: {
      '2018-11-11': {holiday: '节日', tag: 'qiang', price: parseInt(Math.random() * 10000)},
      '2018-11-28': {holiday: '节日', tag: 'qiang', price: parseInt(Math.random() * 10000)},
      '2018-11-29': {holiday: '节日', tag: 'cu', price: parseInt(Math.random() * 10000)},
      '2018-12-01': {holiday: '节日', tag: 'jian', price: parseInt(Math.random() * 10000)},
      '2018-12-02': {holiday: '节日', tag: 'jian', price: parseInt(Math.random() * 10000), num: 0},
      '2018-12-03': {holiday: '节日', tag: 'jian', price: parseInt(Math.random() * 10000)},
      '2018-12-30': {holiday: '休', tag: 'cu', price: parseInt(Math.random() * 10000)},
      '2018-12-31': {holiday: '休', tag: 'cu', price: parseInt(Math.random() * 10000)},
      '2019-01-01': {holiday: '元旦', tag: 'qiang', price: parseInt(Math.random() * 10000)}
    },
    isFull: false,
    gridClick: function (date) {
      console.log(date)
    }
  })
  // 更多优惠券
  $(".show-more-coupon").on("click", function () {
    var coupon = [{},{},{}]
    $.popup({
      title: '优惠券',
      titleAlign: 'center',
      line: false,
      content: _.template($("#more-coupon").html())(coupon)
    });
  })
  // 更多优惠
  $(".show-more-discounts").on("click", function () {
    var discounts = [
      {type: 'cu',typeStr: '促',con: '成人价¥29999，儿童价¥19999'},
      {type: 'jian',typeStr: '减',con: '成人价¥29999，儿童价¥19999'},
      {type: 'yu',typeStr: '预',con: '成人价¥29999，儿童价¥19999'},
      {type: 'zeng',typeStr: '赠',con: '银联用卡奖励注册用卡奖励活动，使用62开头银联卡境外消费满额最高获赠价值900元礼品卡'}
    ]
    $.popup({
      title: '促销',
      titleAlign: 'center',
      line: false,
      content: _.template($("#more-discounts").html())(discounts)
    });
  })
  // 行程介绍图片
  $(".tour-img").each(function () {
    if($(this).find("li").length%2===1){
      $(this).find("li").eq(0).css("width","100%");
    }
  })
  // 侧边栏行程
  $(".show-tour").on("click", function () {
    $(".tour-sidebar").show().addClass("show");
  })
  $(".tour-sidebar").on("click", function (){
    $(this).removeClass("show");
  })
  // toTop
  $(".gzl-asidebar .to-top").on("click", function () {
    $(".gzl-section").toTop();
  })
  // 行程图片弹窗
  var tourdetail = new Swiper('.tourdetail-swiper', {
    loop: true,
    speed: 500,
    pagination: {
      el: '.tourdetail-pagination',
      type: 'fraction'
    }
  });
  //
  var tourimg = new Swiper('.gzl-swiper_fraction', {
    loop: true,
    speed: 500,
    autoHeight: true,
    pagination: {
      el: '.swiper-pagination',
      type: 'fraction'
    }
  });
  //
  $(".tour-img").on("click", function () {
    $(".tourdetail-swiper").addClass("show");
  })
  $(".tourdetail-swiper").on("click", function () {
    $(".tourdetail-swiper").removeClass("show");
  })
  // 滚动事件
  $.scrollTarget({
    docH: $(".detail-section")
  });
  // 下拉
  $(".gzl-section").pullToRefresh(function() {
    setTimeout(function() {
      console.log(123123123)
      $(".gzl-section").pullToRefreshDone();
    }, 500);
  });
});